$package('itsm.news');

itsm.news.topicMain=function(){
	this.opt='';
	return {
		topicTypeForma:function(cell){
			
			if(cell=='menu')
				return '菜单'
			if(cell=='other')
				return '其他'
				
			return "";	
		},
		//列表
		topicMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'topic!findTopicPager.action',
				caption:'栏目列表',
				colNames:['ID','栏目名称','排序','类型','描述'],
			 	colModel:[
			 	          {name:'topicId',align:'center'},
			 	          {name:'topicName',align:'left'},
			 	          {name:'topicOrder',align:'left'},
			 	          {name:'topicType',align:'left',formatter:itsm.news.topicMain.topicTypeForma},
			 	          {name:'description',align:'left'}
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "topicId"}),
				sortname:'topicId',
				pager:'#topicMainPager'
				});
				$("#topicMainGrid").jqGrid(params);
				$("#topicMainGrid").navGrid('#topicMainPager',navGridParams);
				//列表操作项
				$("#t_topicMainGrid").css(jqGridTopStyles);
				$("#t_topicMainGrid").html($('#topicMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#topicMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveTopic';
			resetForm('#topicMain_add_form');
			$('#topicMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editTopic';
			checkBeforeEditGrid('#topicMainGrid',function(rowData){
				$.post('topic!findTopicInfo.action','topicDTO.topicId='+rowData.topicId,function(data){
					$('#topicMain_topicId').val(data.topicId);
					$('#topicMain_topicName').val(data.topicName);
					$('#topicMain_topicOrder').val(data.topicOrder);
					$('#topicMain_topicType').val(data.topicType);
					$('#topicMain_description').val(data.description);
				});
				$('#topicMain_add_win').window('open');
			});	
		},
		
		//保存
		saveTopic:function(){
			if($('#topicMain_add_win').form('validate')){
				var _param = $('#topicMain_add_win form').serialize();
				$.post('topic!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#topicMain_add_win').window('close');
					$('#topicMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteTopic:function(){
			checkBeforeDeleteGrid('#topicMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("topic!deleteTopic.action", pp, function(){
					$('#topicMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
					
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#topicMain_search_win').window('open');
		},
		//搜索
		searchTopic:function(){
			var sdata=$('#topicMain_search_win form').getForm();
			var postData = $("#topicMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'topic!findTopicPager.action';	
			$('#topicMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		init:function(){
			itsm.news.topicMain.topicMainGrid();
		}
	}
	
}();

$(function(){
	itsm.news.topicMain.init();
});